<html><!-- Created using the cpp_pretty_printer from the dlib C++ library.  See http://dlib.net for updates. --><head><title>dlib C++ Library - base_widgets.cpp</title></head><body bgcolor='white'><pre>
<font color='#009900'>// Copyright (C) 2005  Davis E. King (davis@dlib.net), Keita Mochizuki
</font><font color='#009900'>// License: Boost Software License   See LICENSE.txt for the full license.
</font><font color='#0000FF'>#ifndef</font> DLIB_BASE_WIDGETs_CPP_
<font color='#0000FF'>#define</font> DLIB_BASE_WIDGETs_CPP_

<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='base_widgets.h.html'>base_widgets.h</a>"
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='../assert.h.html'>../assert.h</a>"
<font color='#0000FF'>#include</font> <font color='#5555FF'>&lt;</font>iostream<font color='#5555FF'>&gt;</font>


<font color='#0000FF'>namespace</font> dlib
<b>{</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// button object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle min_rect <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_min_size</font><font face='Lucida Console'>(</font>name_,<font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>;
        <font color='#009900'>// only change the size if it isn't going to be too small to fit the name
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>height <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> min_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font>
            width <font color='#5555FF'>&gt;</font><font color='#5555FF'>=</font> min_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_invalidation_rect</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            btn_tooltip.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        button_action::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_tooltip_text'></a>set_tooltip_text</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> ustring<font color='#5555FF'>&amp;</font> text
    <font face='Lucida Console'>)</font>
    <b>{</b>
        btn_tooltip.<font color='#BB00BB'>set_text</font><font face='Lucida Console'>(</font>text<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string button::
    <b><a name='tooltip_text'></a>tooltip_text</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>text</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring button::
    <b><a name='tooltip_wtext'></a>tooltip_wtext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>wtext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring button::
    <b><a name='tooltip_utext'></a>tooltip_utext</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> btn_tooltip.<font color='#BB00BB'>utext</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_main_font'></a>set_main_font</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> shared_ptr_thread_safe<font color='#5555FF'>&lt;</font>font<font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> f
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mfont <font color='#5555FF'>=</font> f;
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font>name_<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        button_action::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::string<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_mbstring_to_wstring</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> std::wstring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_name</font><font face='Lucida Console'>(</font><font color='#BB00BB'>convert_wstring_to_utf32</font><font face='Lucida Console'>(</font>name<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='set_name'></a>set_name</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> ustring<font color='#5555FF'>&amp;</font> name
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        name_ <font color='#5555FF'>=</font> name;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        name_[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> name_[<font color='#979000'>0</font>];

        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_min_size</font><font face='Lucida Console'>(</font>name,<font color='#5555FF'>*</font>mfont<font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        btn_tooltip.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_invalidation_rect</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> std::string button::
    <b><a name='name'></a>name</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        std::string temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_wstring_to_mbstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>wname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::string implementation.
</font>        <font color='#0000FF'><u>char</u></font> c <font color='#5555FF'>=</font> temp[<font color='#979000'>0</font>];
        temp[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> c;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

    <font color='#0000FF'>const</font> std::wstring button::
    <b><a name='wname'></a>wname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        std::wstring temp <font color='#5555FF'>=</font> <font color='#BB00BB'>convert_utf32_to_wstring</font><font face='Lucida Console'>(</font><font color='#BB00BB'>uname</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the std::wstring implementation.
</font>        <font color='#0000FF'><u>wchar_t</u></font> w <font color='#5555FF'>=</font> temp[<font color='#979000'>0</font>];
        temp[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> w;
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

    <font color='#0000FF'>const</font> dlib::ustring button::
    <b><a name='uname'></a>uname</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        dlib::ustring temp <font color='#5555FF'>=</font> name_;
        <font color='#009900'>// do this to get rid of any reference counting that may be present in 
</font>        <font color='#009900'>// the dlib::ustring implementation.
</font>        temp[<font color='#979000'>0</font>] <font color='#5555FF'>=</font> name_[<font color='#979000'>0</font>];
        <font color='#0000FF'>return</font> temp;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='on_button_up'></a>on_button_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> mouse_over
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>mouse_over<font face='Lucida Console'>)</font>                
        <b>{</b>
            <font color='#009900'>// this is a valid button click
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>event_handler_self.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>event_handler_self</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>button_up_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>button_up_handler</font><font face='Lucida Console'>(</font>mouse_over<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>button_up_handler_self.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>button_up_handler_self</font><font face='Lucida Console'>(</font>mouse_over,<font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button::
    <b><a name='on_button_down'></a>on_button_down</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>button_down_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>button_down_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>button_down_handler_self.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>button_down_handler_self</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// draggable object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    draggable::~<b><a name='draggable'></a>draggable</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> draggable::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drag <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// the user is trying to drag this object.  we should calculate the new
</font>            <font color='#009900'>// x and y positions for the upper left corner of this object's rectangle
</font>
            <font color='#0000FF'><u>long</u></font> new_x <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>x;
            <font color='#0000FF'><u>long</u></font> new_y <font color='#5555FF'>=</font> y <font color='#5555FF'>-</font> <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>y;

            <font color='#009900'>// make sure these points are inside the draggable area.  
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_x <font color='#5555FF'>&lt;</font> area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                new_x <font color='#5555FF'>=</font> area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_x <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&gt;</font> area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                new_x <font color='#5555FF'>=</font> area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_y <font color='#5555FF'>+</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&gt;</font> area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                new_y <font color='#5555FF'>=</font> area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_y <font color='#5555FF'>&lt;</font> area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                new_y <font color='#5555FF'>=</font> area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// now make the new rectangle for this object
</font>            rectangle <font color='#BB00BB'>new_rect</font><font face='Lucida Console'>(</font>
                new_x,
                new_y,
                new_x <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>,
                new_y <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>
            <font face='Lucida Console'>)</font>;

            <font color='#009900'>// only do anything if this is a new rectangle and it is inside area
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_rect <font color='#5555FF'>!</font><font color='#5555FF'>=</font> rect <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> area.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>new_rect<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> new_rect<font face='Lucida Console'>)</font>
            <b>{</b>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>new_rect <font color='#5555FF'>+</font> rect<font face='Lucida Console'>)</font>;
                rect <font color='#5555FF'>=</font> new_rect;

                <font color='#009900'>// call the on_drag() event handler
</font>                <font color='#BB00BB'>on_drag</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#BB00BB'>on_drag_stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> draggable::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>drag <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            drag <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#BB00BB'>on_drag_stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> draggable::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            drag <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>x <font color='#5555FF'>=</font> x <font color='#5555FF'>-</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>y <font color='#5555FF'>=</font> y <font color='#5555FF'>-</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// mouse_over_event object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    mouse_over_event::~<b><a name='mouse_over_event'></a>mouse_over_event</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_over_event::
    <b><a name='on_mouse_leave'></a>on_mouse_leave</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_mouse_over_<font face='Lucida Console'>)</font>
        <b>{</b>
            is_mouse_over_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#BB00BB'>on_mouse_not_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_over_event::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_mouse_over_<font face='Lucida Console'>)</font>
            <b>{</b>
                is_mouse_over_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                <font color='#BB00BB'>on_mouse_not_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_mouse_over_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            is_mouse_over_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>on_mouse_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> mouse_over_event::
    <b><a name='is_mouse_over'></a>is_mouse_over</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#009900'>// check if the mouse is still really over this button
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_mouse_over_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// trigger a user event to call on_mouse_not_over() and repaint this object.
</font>            <font color='#009900'>// we must do this in another event because someone might call is_mouse_over()
</font>            <font color='#009900'>// from draw() and you don't want this function to end up calling 
</font>            <font color='#009900'>// parent.invalidate_rectangle().  It would lead to draw() being called over
</font>            <font color='#009900'>// and over.
</font>            parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font color='#5555FF'>*</font><font face='Lucida Console'>)</font><font color='#0000FF'>this</font>,drawable::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> is_mouse_over_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> mouse_over_event::
    <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> num 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_mouse_over_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> num <font color='#5555FF'>=</font><font color='#5555FF'>=</font> drawable::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            is_mouse_over_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#BB00BB'>on_mouse_not_over</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// button_action object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    button_action::~<b><a name='button_action'></a>button_action</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <b>{</b><b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button_action::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            seen_click <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_button_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button_action::
    <b><a name='on_mouse_not_over'></a>on_mouse_not_over</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_<font face='Lucida Console'>)</font>
        <b>{</b>
            is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button_action::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// forward event to the parent class so it can do it's thing as well as us
</font>        mouse_over_event::<font color='#BB00BB'>on_mouse_move</font><font face='Lucida Console'>(</font>state,x,y<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> hidden <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;


        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            seen_click <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_<font face='Lucida Console'>)</font>
            <b>{</b>
                is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#009900'>// the left button isn't down so we don't care about anything else
</font>            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_<font face='Lucida Console'>)</font>
            <b>{</b>
                is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_ <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> seen_click<font face='Lucida Console'>)</font>
        <b>{</b>
            is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_button_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button_action::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_<font face='Lucida Console'>)</font>
            <b>{</b>
                is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>                
                <b>{</b>
                    <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>seen_click <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// this case here covers the unlikly event that you click on a button,
</font>                <font color='#009900'>// move the mouse off the button and then move it back very quickly and
</font>                <font color='#009900'>// release the mouse button.   It is possible that this mouse up event
</font>                <font color='#009900'>// will occurr before any mouse move event so you might not have set
</font>                <font color='#009900'>// that the button is depressed yet.
</font>                
                <font color='#009900'>// So we should say that this triggers an on_button_down() event and
</font>                <font color='#009900'>// then an on_button_up(true) event.
</font>
                parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

                <font color='#BB00BB'>on_button_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font>;
            <b>}</b>

            seen_click <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> button_action::
    <b><a name='is_depressed'></a>is_depressed</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#009900'>// check if the mouse is still really over this button
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> is_depressed_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// trigger a user event to call on_button_up() and repaint this object.
</font>            <font color='#009900'>// we must do this in another event because someone might call is_depressed()
</font>            <font color='#009900'>// from draw() and you don't want this function to end up calling 
</font>            <font color='#009900'>// parent.invalidate_rectangle().  It would lead to draw() being called over
</font>            <font color='#009900'>// and over.
</font>            parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>void</u></font><font color='#5555FF'>*</font><font face='Lucida Console'>)</font><font color='#0000FF'>this</font>,mouse_over_event::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> is_depressed_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> button_action::
    <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> num
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// forward event to the parent class so it can do it's thing as well as us
</font>        mouse_over_event::<font color='#BB00BB'>on_user_event</font><font face='Lucida Console'>(</font>num<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_depressed_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> num <font color='#5555FF'>=</font><font color='#5555FF'>=</font> mouse_over_event::<font color='#BB00BB'>next_free_user_event_number</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            is_depressed_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_button_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    <font color='#009900'>// scroll_bar object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    scroll_bar::
    <b><a name='scroll_bar'></a>scroll_bar</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w,
        bar_orientation orientation 
    <font face='Lucida Console'>)</font> :
        drawable<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        b1<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        b2<font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>,
        slider<font face='Lucida Console'>(</font>w,<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::on_slider_drag<font face='Lucida Console'>)</font>,
        ori<font face='Lucida Console'>(</font>orientation<font face='Lucida Console'>)</font>,
        top_filler<font face='Lucida Console'>(</font>w,<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::top_filler_down,<font color='#5555FF'>&amp;</font>scroll_bar::top_filler_up<font face='Lucida Console'>)</font>,
        bottom_filler<font face='Lucida Console'>(</font>w,<font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::bottom_filler_down,<font color='#5555FF'>&amp;</font>scroll_bar::bottom_filler_up<font face='Lucida Console'>)</font>,
        pos<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        max_pos<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        js<font face='Lucida Console'>(</font><font color='#979000'>10</font><font face='Lucida Console'>)</font>,
        b1_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b1_down_t<font face='Lucida Console'>)</font>,
        b2_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b2_down_t<font face='Lucida Console'>)</font>,
        top_filler_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::top_filler_down_t<font face='Lucida Console'>)</font>,
        bottom_filler_timer<font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::bottom_filler_down_t<font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>set_style</font><font face='Lucida Console'>(</font><font color='#BB00BB'>scroll_bar_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// don't show the slider when there is no place it can move.
</font>        slider.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font><font color='#979000'>100</font><font face='Lucida Console'>)</font>;

        b1.<font color='#BB00BB'>set_button_down_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b1_down<font face='Lucida Console'>)</font>;
        b2.<font color='#BB00BB'>set_button_down_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b2_down<font face='Lucida Console'>)</font>;

        b1.<font color='#BB00BB'>set_button_up_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b1_up<font face='Lucida Console'>)</font>;
        b2.<font color='#BB00BB'>set_button_up_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scroll_bar::b2_up<font face='Lucida Console'>)</font>;
        b1.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        b2.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    scroll_bar::
    ~<b><a name='scroll_bar'></a>scroll_bar</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>; 
        <font color='#009900'>// wait for all the timers to be stopped
</font>        b1_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        b2_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        top_filler_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler_timer.<font color='#BB00BB'>stop_and_wait</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    scroll_bar::bar_orientation scroll_bar::
    <b><a name='orientation'></a>orientation</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> ori;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>    
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='set_length'></a>set_length</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> length
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#009900'>// make the min length be at least 1
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>length <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            length <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
        <b>}</b>


        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> length <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> btn_size <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_button_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pos<font face='Lucida Console'>)</font>;

            b1.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>btn_size,style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            b2.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>btn_size,style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            slider.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font><font color='#BB00BB'>get_slider_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            rect.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            rect.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> length <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> btn_size <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_button_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, max_pos<font face='Lucida Console'>)</font>;

            b1.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,btn_size<font face='Lucida Console'>)</font>;
            b2.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,btn_size<font face='Lucida Console'>)</font>;

            slider.<font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,<font color='#BB00BB'>get_slider_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// call this to put everything is in the right spot.
</font>        <font color='#BB00BB'>set_pos</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>8</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> VERTICAL<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
            <font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>8</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
            max_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>hide_slider</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>show_slider</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;

        b1.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// make the b2 button appear at the end of the scroll_bar
</font>            b2.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>max_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>double</u></font> range <font color='#5555FF'>=</font> b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
                <font color='#0000FF'><u>double</u></font> slider_pos <font color='#5555FF'>=</font> pos;
                slider_pos <font color='#5555FF'>/</font><font color='#5555FF'>=</font> max_pos;
                slider_pos <font color='#5555FF'>*</font><font color='#5555FF'>=</font> range;
                slider.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>
                    <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slider_pos<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                    rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                    <font face='Lucida Console'>)</font>;

                <font color='#009900'>// move the draggable area for the slider to the new location
</font>                rectangle area <font color='#5555FF'>=</font> rect;
                area.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>area.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                area.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>area.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                slider.<font color='#BB00BB'>set_draggable_area</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font>;

            <b>}</b>

            
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#009900'>// make the b2 button appear at the end of the scroll_bar
</font>            b2.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>max_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>double</u></font> range <font color='#5555FF'>=</font> b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
                <font color='#0000FF'><u>double</u></font> slider_pos <font color='#5555FF'>=</font> pos;
                slider_pos <font color='#5555FF'>/</font><font color='#5555FF'>=</font> max_pos;
                slider_pos <font color='#5555FF'>*</font><font color='#5555FF'>=</font> range;
                slider.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>
                    rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, 
                    <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slider_pos<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
                    <font face='Lucida Console'>)</font>;

                <font color='#009900'>// move the draggable area for the slider to the new location
</font>                rectangle area <font color='#5555FF'>=</font> rect;
                area.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>area.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                area.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>area.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
                slider.<font color='#BB00BB'>set_draggable_area</font><font face='Lucida Console'>(</font>area<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        <font color='#BB00BB'>adjust_fillers</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scroll_bar::
    <b><a name='get_slider_size'></a>get_slider_size</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_slider_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,max_pos<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#0000FF'>return</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_slider_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,max_pos<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='adjust_fillers'></a>adjust_fillers</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        rectangle <font color='#BB00BB'>top</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>, <font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                top.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                top.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                top.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                top.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                top.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                top.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                top.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                top.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
                bottom.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>

        top_filler.rect <font color='#5555FF'>=</font> top;
        bottom_filler.rect <font color='#5555FF'>=</font> bottom;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='hide_slider'></a>hide_slider</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        rectangle <font color='#BB00BB'>top</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>, <font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        slider.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        top_filler.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            top.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            top.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            top.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            top.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        top_filler.rect <font color='#5555FF'>=</font> top;
        bottom_filler.rect <font color='#5555FF'>=</font> bottom;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='show_slider'></a>show_slider</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>8</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> VERTICAL<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
            <font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font> <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> <font color='#979000'>8</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> 
            max_pos <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font>;

        rectangle <font color='#BB00BB'>top</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>, <font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        slider.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        top_filler.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            top.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            top.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            bottom.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            bottom.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            top.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            top.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            bottom.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            bottom.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        top_filler.rect <font color='#5555FF'>=</font> top;
        bottom_filler.rect <font color='#5555FF'>=</font> bottom;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>long</u></font> scroll_bar::
    <b><a name='max_slider_pos'></a>max_slider_pos</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> max_pos;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='set_max_slider_pos'></a>set_max_slider_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> mpos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        max_pos <font color='#5555FF'>=</font> mpos;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>&gt;</font> mpos<font face='Lucida Console'>)</font>
            pos <font color='#5555FF'>=</font> mpos;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
            <font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            <font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>mpos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled<font face='Lucida Console'>)</font>
        <b>{</b>
            b1.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            b2.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            b1.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            b2.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
             
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='set_slider_pos'></a>set_slider_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            pos <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>&gt;</font> max_pos<font face='Lucida Console'>)</font>
            pos <font color='#5555FF'>=</font> max_pos;

        <font color='#0000FF'>this</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font>pos <font color='#5555FF'>=</font> pos;

        <font color='#009900'>// move the slider object to its new position
</font>        <font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>long</u></font> scroll_bar::
    <b><a name='slider_pos'></a>slider_pos</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> pos;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='on_slider_drag'></a>on_slider_drag</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>ori <font color='#5555FF'>=</font><font color='#5555FF'>=</font> HORIZONTAL<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> slider_pos <font color='#5555FF'>=</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            <font color='#0000FF'><u>double</u></font> range <font color='#5555FF'>=</font> b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            slider_pos <font color='#5555FF'>/</font><font color='#5555FF'>=</font> range;
            slider_pos <font color='#5555FF'>*</font><font color='#5555FF'>=</font> max_pos;
            pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slider_pos<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#0000FF'><u>double</u></font> slider_pos <font color='#5555FF'>=</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            <font color='#0000FF'><u>double</u></font> range <font color='#5555FF'>=</font> b2.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> b1.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> slider.<font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font>;
            slider_pos <font color='#5555FF'>/</font><font color='#5555FF'>=</font> range;
            slider_pos <font color='#5555FF'>*</font><font color='#5555FF'>=</font> max_pos;
            pos <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>slider_pos<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#BB00BB'>adjust_fillers</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scroll_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>scroll_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> 
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b1_down'></a>b1_down</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scroll_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>scroll_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>b1_timer.<font color='#BB00BB'>delay_time</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1000</font><font face='Lucida Console'>)</font>
                b1_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                b1_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>50</font><font face='Lucida Console'>)</font>;
            b1_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b1_up'></a>b1_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        b1_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        b1_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>1000</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b2_down'></a>b2_down</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> max_pos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scroll_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#BB00BB'>scroll_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>b2_timer.<font color='#BB00BB'>delay_time</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1000</font><font face='Lucida Console'>)</font>
                b2_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                b2_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>50</font><font face='Lucida Console'>)</font>;
            b2_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b2_up'></a>b2_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        b2_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        b2_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>1000</font><font face='Lucida Console'>)</font>;
    <b>}</b>
        
<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='top_filler_down'></a>top_filler_down</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// ignore this if the mouse is now outside this object.  This could happen
</font>        <font color='#009900'>// since the timers are also calling this function.
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>top_filler.rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>top_filler_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>&lt;</font> js<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if there is less than jump_size() space left then jump the remaining
</font>                <font color='#009900'>// amount.
</font>                <font color='#BB00BB'>delayed_set_slider_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#BB00BB'>delayed_set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>-</font>js<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>top_filler_timer.<font color='#BB00BB'>delay_time</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1000</font><font face='Lucida Console'>)</font>
                top_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                top_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>50</font><font face='Lucida Console'>)</font>;
            top_filler_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='top_filler_up'></a>top_filler_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        top_filler_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        top_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>1000</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='bottom_filler_down'></a>bottom_filler_down</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// ignore this if the mouse is now outside this object.  This could happen
</font>        <font color='#009900'>// since the timers are also calling this function.
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bottom_filler.rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>bottom_filler_up</font><font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> max_pos<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>max_pos <font color='#5555FF'>-</font> pos <font color='#5555FF'>&lt;</font> js<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#009900'>// if there is less than jump_size() space left then jump the remaining
</font>                <font color='#009900'>// amount.
</font>                <font color='#BB00BB'>delayed_set_slider_pos</font><font face='Lucida Console'>(</font>max_pos<font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font>
            <b>{</b>
                <font color='#BB00BB'>delayed_set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font>js<font face='Lucida Console'>)</font>;
            <b>}</b>

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>bottom_filler_timer.<font color='#BB00BB'>delay_time</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1000</font><font face='Lucida Console'>)</font>
                bottom_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>500</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>else</font>
                bottom_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>50</font><font face='Lucida Console'>)</font>;
            bottom_filler_timer.<font color='#BB00BB'>start</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='bottom_filler_up'></a>bottom_filler_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        bottom_filler_timer.<font color='#BB00BB'>stop</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        bottom_filler_timer.<font color='#BB00BB'>set_delay_time</font><font face='Lucida Console'>(</font><font color='#979000'>1000</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='set_jump_size'></a>set_jump_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> js_
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>js_ <font color='#5555FF'>&lt;</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font>
            js <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
        <font color='#0000FF'>else</font>
            js <font color='#5555FF'>=</font> js_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>long</u></font> scroll_bar::
    <b><a name='jump_size'></a>jump_size</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> js;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='on_user_event'></a>on_user_event</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>int</u></font> i
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>switch</font> <font face='Lucida Console'>(</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>case</font> <font color='#979000'>0</font>:
                <font color='#BB00BB'>b1_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>break</font>;
            <font color='#0000FF'>case</font> <font color='#979000'>1</font>:
                <font color='#BB00BB'>b2_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>break</font>;
            <font color='#0000FF'>case</font> <font color='#979000'>2</font>:
                <font color='#BB00BB'>top_filler_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>break</font>;
            <font color='#0000FF'>case</font> <font color='#979000'>3</font>:
                <font color='#BB00BB'>bottom_filler_down</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>break</font>;
            <font color='#0000FF'>case</font> <font color='#979000'>4</font>:
                <font color='#009900'>// if the position we are supposed to switch the slider too isn't 
</font>                <font color='#009900'>// already set
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>delayed_pos <font color='#5555FF'>!</font><font color='#5555FF'>=</font> pos<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>delayed_pos<font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scroll_handler.<font color='#BB00BB'>is_set</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <font color='#BB00BB'>scroll_handler</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>break</font>;
            <font color='#0000FF'>default</font>:
                <font color='#0000FF'>break</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='delayed_set_slider_pos'></a>delayed_set_slider_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> dpos
    <font face='Lucida Console'>)</font> 
    <b>{</b>
        delayed_pos <font color='#5555FF'>=</font> dpos;
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,<font color='#979000'>4</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b1_down_t'></a>b1_down_t</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='b2_down_t'></a>b2_down_t</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,<font color='#979000'>1</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='top_filler_down_t'></a>top_filler_down_t</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,<font color='#979000'>2</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scroll_bar::
    <b><a name='bottom_filler_down_t'></a>bottom_filler_down_t</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b> 
        parent.<font color='#BB00BB'>trigger_user_event</font><font face='Lucida Console'>(</font><font color='#0000FF'>this</font>,<font color='#979000'>3</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//                  widget_group object methods  
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='empty'></a>empty</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> 
    <b>{</b>  
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        widgets.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
        wg_widgets.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='add'></a>add</b> <font face='Lucida Console'>(</font>
        drawable<font color='#5555FF'>&amp;</font> widget,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        drawable<font color='#5555FF'>*</font> w <font color='#5555FF'>=</font> <font color='#5555FF'>&amp;</font>widget;
        relpos rp;
        rp.x <font color='#5555FF'>=</font> x;
        rp.y <font color='#5555FF'>=</font> y;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>is_in_domain</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            widgets[w].x <font color='#5555FF'>=</font> x;
            widgets[w].y <font color='#5555FF'>=</font> y;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            widgets.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font>w,rp<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_hidden</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widget.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            widget.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_enabled</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widget.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>else</font>
            widget.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        widget.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font><font color='#BB00BB'>z_order</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        widget.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>+</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,y<font color='#5555FF'>+</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='add'></a>add</b> <font face='Lucida Console'>(</font>
        widget_group<font color='#5555FF'>&amp;</font> widget,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        drawable<font color='#5555FF'>&amp;</font> w <font color='#5555FF'>=</font> widget;
        <font color='#BB00BB'>add</font><font face='Lucida Console'>(</font>w, x, y<font face='Lucida Console'>)</font>;

        widget_group<font color='#5555FF'>*</font> wg <font color='#5555FF'>=</font> <font color='#5555FF'>&amp;</font>widget;
        wg_widgets.<font color='#BB00BB'>add</font><font face='Lucida Console'>(</font>wg<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> widget_group::
    <b><a name='is_member'></a>is_member</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> drawable<font color='#5555FF'>&amp;</font> widget
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
    <b>{</b> 
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        drawable<font color='#5555FF'>*</font> w <font color='#5555FF'>=</font> <font color='#0000FF'>const_cast</font><font color='#5555FF'>&lt;</font>drawable<font color='#5555FF'>*</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>widget<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> widgets.<font color='#BB00BB'>is_in_domain</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='remove'></a>remove</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> drawable<font color='#5555FF'>&amp;</font> widget
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        drawable<font color='#5555FF'>*</font> w <font color='#5555FF'>=</font> <font color='#0000FF'>const_cast</font><font color='#5555FF'>&lt;</font>drawable<font color='#5555FF'>*</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#5555FF'>&amp;</font>widget<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>is_in_domain</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            widgets.<font color='#BB00BB'>destroy</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;

            <font color='#009900'>// check if we also have an entry in the wg_widgets set and if
</font>            <font color='#009900'>// so then remove that too
</font>            widget_group<font color='#5555FF'>*</font> wg <font color='#5555FF'>=</font> <font color='#0000FF'>reinterpret_cast</font><font color='#5555FF'>&lt;</font>widget_group<font color='#5555FF'>*</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>w<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>wg_widgets.<font color='#BB00BB'>is_member</font><font face='Lucida Console'>(</font>wg<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                wg_widgets.<font color='#BB00BB'>destroy</font><font face='Lucida Console'>(</font>wg<font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> widget_group::
    <b><a name='size'></a>size</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
    <b>{</b>  
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>; 
        <font color='#0000FF'>return</font> widgets.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> rx <font color='#5555FF'>=</font> widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>value</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.x;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ry <font color='#5555FF'>=</font> widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>value</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.y;
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x<font color='#5555FF'>+</font>rx,y<font color='#5555FF'>+</font>ry<font face='Lucida Console'>)</font>;
        <b>}</b>
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='set_z_order'></a>set_z_order</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> order
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> widget_group::
    <b><a name='fit_to_contents'></a>fit_to_contents</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        <font color='#009900'>// call fit_to_contents on all the widget_groups we contain
</font>        wg_widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>wg_widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            wg_widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>fit_to_contents</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// now accumulate a rectangle that contains everything in this widget_group
</font>        rectangle r;
        widgets.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>widgets.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            r <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> widgets.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>is_empty</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// make sure it is still empty after we set it at the correct position 
</font>            r.<font color='#BB00BB'>set_right</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            r.<font color='#BB00BB'>set_bottom</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        r.<font color='#BB00BB'>set_left</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        r.<font color='#BB00BB'>set_top</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> r;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//                class popup_menu
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    popup_menu::
    <b><a name='popup_menu'></a>popup_menu</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> :
        base_window<font face='Lucida Console'>(</font><font color='#979000'>false</font>,<font color='#979000'>true</font><font face='Lucida Console'>)</font>,
        pad<font face='Lucida Console'>(</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>,
        item_pad<font face='Lucida Console'>(</font><font color='#979000'>3</font><font face='Lucida Console'>)</font>,
        cur_rect<font face='Lucida Console'>(</font>pad,pad,pad<font color='#5555FF'>-</font><font color='#979000'>1</font>,pad<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        left_width<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        middle_width<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        selected_item<font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>,
        submenu_open<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='enable_menu_item'></a>enable_menu_item</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tvoid popup_menu::enable_menu_item()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:    </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        item_enabled[idx] <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>cur_rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='disable_menu_item'></a>disable_menu_item</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> idx
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font> <font face='Lucida Console'>(</font> idx <font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> ,
                      "<font color='#CC0000'>\tvoid popup_menu::enable_menu_item()</font>"
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tidx:    </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> idx
                      <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tsize(): </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
        <font face='Lucida Console'>)</font>;
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        item_enabled[idx] <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>cur_rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> popup_menu::
    <b><a name='size'></a>size</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b> 
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='clear'></a>clear</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        cur_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>pad,pad,pad<font color='#5555FF'>-</font><font color='#979000'>1</font>,pad<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        win_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        left_width <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        middle_width <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        items.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        item_enabled.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        left_rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        middle_rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        right_rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        line_rects.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        submenus.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        selected_item <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        submenu_open <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        selected_item <font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        base_window::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#009900'>// hide ourselves
</font>        <font color='#BB00BB'>close_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        selected_item <font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        base_window::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='select_first_item'></a>select_first_item</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>close_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        selected_item <font color='#5555FF'>=</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> item_enabled[i]<font face='Lucida Console'>)</font>
            <b>{</b>
                selected_item <font color='#5555FF'>=</font> i;
                <font color='#0000FF'>break</font>;
            <b>}</b>
        <b>}</b>
        <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>cur_rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> popup_menu::
    <b><a name='forwarded_on_keydown'></a>forwarded_on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>wm<font face='Lucida Console'>)</font>;
        <font color='#009900'>// do nothing if this popup menu is empty
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <font color='#0000FF'>return</font> <font color='#979000'>false</font>;


        <font color='#009900'>// check if the selected item is a submenu
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenus[selected_item] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenu_open<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// send the key to the submenu and return if that menu used the key
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>submenus[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>forwarded_on_keydown</font><font face='Lucida Console'>(</font>key,is_printable,state<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>true</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> KEY_UP<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                selected_item <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>+</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font>items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// only stop looking if this one is enabled and has a click event or is a submenu
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item_enabled[selected_item] <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>items[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[selected_item]<font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>
                    <font color='#0000FF'>break</font>;
            <b>}</b>
            <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>cur_rect<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> KEY_DOWN<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                selected_item <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>+</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>%</font>items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#009900'>// only stop looking if this one is enabled and has a click event or is a submenu
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>item_enabled[selected_item] <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>items[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[selected_item]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                    <font color='#0000FF'>break</font>;
            <b>}</b>
            <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>cur_rect<font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> KEY_RIGHT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenu_open <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>display_selected_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            submenus[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> KEY_LEFT <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                 submenus[selected_item] <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenu_open<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>close_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>items[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[selected_item]<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> idx <font color='#5555FF'>=</font> selected_item;
                <font color='#009900'>// only hide this popup window if this isn't a submenu
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>submenus[idx] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    hide_handlers.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>hide_handlers.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        hide_handlers.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                <font color='#0000FF'>else</font>
                <b>{</b>
                    <font color='#BB00BB'>display_selected_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    submenus[idx]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
                items[idx]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>on_click</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <b>}</b>
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>is_printable<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// check if there is a hotkey for this key
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>key<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>tolower</font><font face='Lucida Console'>(</font>items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_hot_key</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                    <font face='Lucida Console'>(</font>items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[i]<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> item_enabled[i] <font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// only hide this popup window if this isn't a submenu
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>submenus[i] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        hide_handlers.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>hide_handlers.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            hide_handlers.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    <font color='#0000FF'>else</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>line_rects[selected_item]<font face='Lucida Console'>)</font>;

                        selected_item <font color='#5555FF'>=</font> i;
                        <font color='#BB00BB'>display_selected_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>line_rects[i]<font face='Lucida Console'>)</font>;
                        submenus[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>select_first_item</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>on_click</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>

            <font color='#009900'>// always say we use a printable key for hotkeys
</font>            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>

        <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='on_submenu_hide'></a>on_submenu_hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hide_handlers.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>hide_handlers.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            hide_handlers.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='on_window_resized'></a>on_window_resized</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>win_rect<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font>,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cur_rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// figure out which item this was on 
</font>            <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>line_rects[i].<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> item_enabled[i] <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#009900'>// only hide this popup window if this isn't a submenu
</font>                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>submenus[i] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        hide_handlers.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                        <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>hide_handlers.<font color='#BB00BB'>move_next</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                            hide_handlers.<font color='#BB00BB'>element</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <b>}</b>
                    items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>on_click</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#0000FF'>break</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>cur_rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// check if the mouse is still in the same rect it was in last time
</font>            rectangle last_rect;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                last_rect <font color='#5555FF'>=</font> line_rects[selected_item];
            <b>}</b>

            <font color='#009900'>// if the mouse isn't in the same rectangle any more
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>last_rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>false</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>last_rect<font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>close_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    selected_item <font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                <b>}</b>


                <font color='#009900'>// figure out if we should redraw any menu items 
</font>                <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>has_click_event</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> submenus[i]<font face='Lucida Console'>)</font>
                    <b>{</b>
                        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>line_rects[i].<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                        <b>{</b>
                            selected_item <font color='#5555FF'>=</font> i;
                            <font color='#0000FF'>break</font>;
                        <b>}</b>
                    <b>}</b>
                <b>}</b>

                <font color='#009900'>// if we found a rectangle that contains the mouse then
</font>                <font color='#009900'>// tell it to redraw itself
</font>                <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <b>{</b>
                    <font color='#BB00BB'>display_selected_submenu</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                    <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>line_rects[selected_item]<font face='Lucida Console'>)</font>;
                <b>}</b>
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='close_submenu'></a>close_submenu</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenus[selected_item] <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenu_open<font face='Lucida Console'>)</font>
        <b>{</b>
            submenus[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            submenu_open <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> popup_menu::
    <b><a name='display_selected_submenu'></a>display_selected_submenu</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// show the submenu if one exists
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> submenus[selected_item]<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> wx, wy;
            <font color='#BB00BB'>get_pos</font><font face='Lucida Console'>(</font>wx,wy<font face='Lucida Console'>)</font>;
            wx <font color='#5555FF'>+</font><font color='#5555FF'>=</font> line_rects[selected_item].<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            wy <font color='#5555FF'>+</font><font color='#5555FF'>=</font> line_rects[selected_item].<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            submenus[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>wx<font color='#5555FF'>+</font><font color='#979000'>1</font>,wy<font color='#5555FF'>-</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
            submenus[selected_item]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            submenu_open <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='on_mouse_leave'></a>on_mouse_leave</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// only unhighlight a menu item if it isn't a submenu item
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>submenus[selected_item] <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>line_rects[selected_item]<font face='Lucida Console'>)</font>;
                selected_item <font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu::
    <b><a name='paint'></a>paint</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font>
    <b>{</b>
        c.<font color='#BB00BB'>fill</font><font face='Lucida Console'>(</font><font color='#979000'>200</font>,<font color='#979000'>200</font>,<font color='#979000'>200</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>draw_rectangle</font><font face='Lucida Console'>(</font>c, win_rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'>&lt;</font> items.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>bool</u></font> is_selected <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>selected_item <font color='#5555FF'>!</font><font color='#5555FF'>=</font> submenus.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> i <font color='#5555FF'>=</font><font color='#5555FF'>=</font> selected_item <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                item_enabled[i]<font face='Lucida Console'>)</font>
                is_selected <font color='#5555FF'>=</font> <font color='#979000'>true</font>;

            items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_background</font><font face='Lucida Console'>(</font>c,line_rects[i], item_enabled[i], is_selected<font face='Lucida Console'>)</font>;
            items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_left</font><font face='Lucida Console'>(</font>c,left_rects[i], item_enabled[i], is_selected<font face='Lucida Console'>)</font>;
            items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_middle</font><font face='Lucida Console'>(</font>c,middle_rects[i], item_enabled[i], is_selected<font face='Lucida Console'>)</font>;
            items[i]<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_right</font><font face='Lucida Console'>(</font>c,right_rects[i], item_enabled[i], is_selected<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//              class zoomable_region
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    zoomable_region::
    <b><a name='zoomable_region'></a>zoomable_region</b> <font face='Lucida Console'>(</font>
        drawable_window<font color='#5555FF'>&amp;</font> w,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> events 
    <font face='Lucida Console'>)</font> :
        drawable<font face='Lucida Console'>(</font>w,MOUSE_CLICK <font color='#5555FF'>|</font> MOUSE_WHEEL <font color='#5555FF'>|</font> MOUSE_MOVE <font color='#5555FF'>|</font> events<font face='Lucida Console'>)</font>,
        min_scale<font face='Lucida Console'>(</font><font color='#979000'>0.15</font><font face='Lucida Console'>)</font>,
        max_scale<font face='Lucida Console'>(</font><font color='#979000'>1.0</font><font face='Lucida Console'>)</font>,
        zoom_increment_<font face='Lucida Console'>(</font><font color='#979000'>0.90</font><font face='Lucida Console'>)</font>,
        vsb<font face='Lucida Console'>(</font>w, scroll_bar::VERTICAL<font face='Lucida Console'>)</font>,
        hsb<font face='Lucida Console'>(</font>w, scroll_bar::HORIZONTAL<font face='Lucida Console'>)</font>
    <b>{</b>
        scale <font color='#5555FF'>=</font> <font color='#979000'>1</font>;
        mouse_drag_screen <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>scrollable_region_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        hsb.<font color='#BB00BB'>set_scroll_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>zoomable_region::on_h_scroll<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_scroll_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>zoomable_region::on_v_scroll<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    zoomable_region::
    ~<b><a name='zoomable_region'></a>zoomable_region</b><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> 
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> border_size <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>+</font><font color='#979000'>1</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size<font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>+</font><font color='#979000'>1</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,
                                  rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,
                                  rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                  rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_zoom_increment'></a>set_zoom_increment</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> zi
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font color='#979000'>0.0</font> <font color='#5555FF'>&lt;</font> zi <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> zi <font color='#5555FF'>&lt;</font> <font color='#979000'>1.0</font>,
                    "<font color='#CC0000'>\tvoid zoomable_region::set_zoom_increment(zi)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t the zoom increment must be between 0 and 1</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t zi:   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> zi
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t this: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        zoom_increment_ <font color='#5555FF'>=</font> zi;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> zoomable_region::
    <b><a name='zoom_increment'></a>zoom_increment</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> zoom_increment_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_max_zoom_scale'></a>set_max_zoom_scale</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> ms 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>ms <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font>,
                    "<font color='#CC0000'>\tvoid zoomable_region::set_max_zoom_scale(ms)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t the max zoom scale must be greater than 0</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t ms:   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> ms 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t this: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        max_scale <font color='#5555FF'>=</font> ms;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>&gt;</font> ms<font face='Lucida Console'>)</font>
        <b>{</b>
            scale <font color='#5555FF'>=</font> max_scale;
            lr_point <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_min_zoom_scale'></a>set_min_zoom_scale</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> ms 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font>ms <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font>,
                    "<font color='#CC0000'>\tvoid zoomable_region::set_min_zoom_scale(ms)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t the min zoom scale must be greater than 0</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t ms:   </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> ms 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\t this: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        min_scale <font color='#5555FF'>=</font> ms;

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>&lt;</font> ms<font face='Lucida Console'>)</font>
        <b>{</b>
            scale <font color='#5555FF'>=</font> min_scale;
        <b>}</b>

        <font color='#009900'>// just call set_size so that everything gets redrawn right
</font>        <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> zoomable_region::
    <b><a name='min_zoom_scale'></a>min_zoom_scale</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> min_scale;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> zoomable_region::
    <b><a name='max_zoom_scale'></a>max_zoom_scale</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> max_scale;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> border_size <font color='#5555FF'>=</font> style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>+</font><font color='#979000'>1</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,  rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size<font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,  rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>+</font><font color='#979000'>1</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,
                                  rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>border_size,
                                  rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                  rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>border_size<font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> old_scale <font color='#5555FF'>=</font> scale;
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>old_gr_orig</font><font face='Lucida Console'>(</font>gr_orig<font face='Lucida Console'>)</font>;
        scale <font color='#5555FF'>=</font> min_scale;
        gr_orig <font color='#5555FF'>=</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font><font color='#979000'>0</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        lr_point <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        scale <font color='#5555FF'>=</font> old_scale;

        <font color='#009900'>// call adjust_origin() so that the scroll bars get their max slider positions
</font>        <font color='#009900'>// setup right
</font>        <font color='#0000FF'>const</font> point <font color='#BB00BB'>rect_corner</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font>rect_corner, old_gr_orig<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_z_order'></a>set_z_order</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> order
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    point zoomable_region::
    <b><a name='graph_to_gui_space'></a>graph_to_gui_space</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>rect_corner</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>p <font color='#5555FF'>-</font> gr_orig<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>scale <font color='#5555FF'>+</font> rect_corner;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> zoomable_region::
    <b><a name='gui_to_graph_space'></a>gui_to_graph_space</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>rect_corner</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>p <font color='#5555FF'>-</font> rect_corner<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>scale <font color='#5555FF'>+</font> gr_orig;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    point zoomable_region::
    <b><a name='max_graph_point'></a>max_graph_point</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> lr_point;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    rectangle zoomable_region::
    <b><a name='display_rect'></a>display_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> 
    <b>{</b>
        <font color='#0000FF'>return</font> display_rect_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>double</u></font> zoomable_region::
    <b><a name='zoom_scale'></a>zoom_scale</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> scale;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='set_zoom_scale'></a>set_zoom_scale</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>double</u></font> new_scale
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// if new_scale isn't in the right range then put it back in range before we do the 
</font>        <font color='#009900'>// rest of this function
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font face='Lucida Console'>(</font>min_scale <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> new_scale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> new_scale <font color='#5555FF'>&lt;</font><font color='#5555FF'>=</font> max_scale<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>new_scale <font color='#5555FF'>&gt;</font> max_scale<font face='Lucida Console'>)</font>
                new_scale <font color='#5555FF'>=</font> max_scale;
            <font color='#0000FF'>else</font>
                new_scale <font color='#5555FF'>=</font> min_scale;
        <b>}</b>

        <font color='#009900'>// find the point in the center of the graph area
</font>        point <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>,  <font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        point <font color='#BB00BB'>graph_p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>center<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        scale <font color='#5555FF'>=</font> new_scale;
        <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font>center, graph_p<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='center_display_at_graph_point'></a>center_display_at_graph_point</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> p
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// find the point in the center of the graph area
</font>        point <font color='#BB00BB'>center</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font>,  <font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font>center, p<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_wheel_down'></a>on_wheel_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// zoom out
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> scale <font color='#5555FF'>&gt;</font> min_scale <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> display_rect_.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            point <font color='#BB00BB'>gui_p</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font>;
            point <font color='#BB00BB'>graph_p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>gui_p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> old_scale <font color='#5555FF'>=</font> scale;
            scale <font color='#5555FF'>*</font><font color='#5555FF'>=</font> zoom_increment_;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>&lt;</font> min_scale<font face='Lucida Console'>)</font>
                scale <font color='#5555FF'>=</font> min_scale;
            <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
            <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font>gui_p, graph_p<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> old_scale<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_wheel_up'></a>on_wheel_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#009900'>// zoom in 
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> scale <font color='#5555FF'>&lt;</font> max_scale  <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> display_rect_.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            point <font color='#BB00BB'>gui_p</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font>;
            point <font color='#BB00BB'>graph_p</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>gui_p<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> old_scale <font color='#5555FF'>=</font> scale;
            scale <font color='#5555FF'>/</font><font color='#5555FF'>=</font> zoom_increment_;
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>&gt;</font> max_scale<font face='Lucida Console'>)</font>
                scale <font color='#5555FF'>=</font> max_scale;
            <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; 
            <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font>gui_p, graph_p<font face='Lucida Console'>)</font>;

            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>scale <font color='#5555FF'>!</font><font color='#5555FF'>=</font> old_scale<font face='Lucida Console'>)</font>
                <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> mouse_drag_screen<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#BB00BB'>adjust_origin</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>, drag_screen_point<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// check if the mouse isn't being dragged anymore
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>state <font color='#5555FF'>&amp;</font> base_window::LEFT<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
        <b>{</b>
            mouse_drag_screen <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_mouse_up'></a>on_mouse_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        mouse_drag_screen <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> display_rect_.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            mouse_drag_screen <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
            drag_screen_point <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_scrollable_region_border</font><font face='Lucida Console'>(</font>c, rect, enabled<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_h_scroll'></a>on_h_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        gr_orig.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='on_v_scroll'></a>on_v_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        gr_orig.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>redraw_graph</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='redraw_graph'></a>redraw_graph</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>display_rect_<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> zoomable_region::
    <b><a name='adjust_origin'></a>adjust_origin</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> point<font color='#5555FF'>&amp;</font> gui_p,
        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font><font color='#5555FF'>&amp;</font> graph_p
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>const</font> point <font color='#BB00BB'>rect_corner</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> dlib::vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>v</font><font face='Lucida Console'>(</font>gui_p <font color='#5555FF'>-</font> rect_corner<font face='Lucida Console'>)</font>;
        gr_orig <font color='#5555FF'>=</font> graph_p <font color='#5555FF'>-</font> v<font color='#5555FF'>/</font>scale;


        <font color='#009900'>// make sure the origin isn't outside the point (0,0)
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gr_orig.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            gr_orig.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>gr_orig.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>
            gr_orig.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>;

        <font color='#009900'>// make sure the lower right corner of the display_rect_ doesn't map to a point beyond lr_point
</font>        point <font color='#BB00BB'>lr_rect_corner</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        point p <font color='#5555FF'>=</font> <font color='#BB00BB'>graph_to_gui_space</font><font face='Lucida Console'>(</font>lr_point<font face='Lucida Console'>)</font>;
        vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>lr_rect_corner_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>lr_rect_corner<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>delta</font><font face='Lucida Console'>(</font>lr_point <font color='#5555FF'>-</font> lr_rect_corner_graph_space<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lr_rect_corner.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> p.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            gr_orig.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> delta.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lr_rect_corner.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> p.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            gr_orig.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>+</font><font color='#5555FF'>=</font> delta.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>


        <font color='#0000FF'>const</font> vector<font color='#5555FF'>&lt;</font><font color='#0000FF'><u>double</u></font>,<font color='#979000'>2</font><font color='#5555FF'>&gt;</font> <font color='#BB00BB'>ul_rect_corner_graph_space</font><font face='Lucida Console'>(</font><font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>rect_corner<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        lr_rect_corner_graph_space <font color='#5555FF'>=</font> <font color='#BB00BB'>gui_to_graph_space</font><font face='Lucida Console'>(</font>lr_rect_corner<font face='Lucida Console'>)</font>;
        <font color='#009900'>// now adjust the scroll bars
</font>
        hsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>lr_point.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font face='Lucida Console'>(</font>lr_rect_corner_graph_space.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>ul_rect_corner_graph_space.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,<font color='#979000'>0.0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>lr_point.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font face='Lucida Console'>(</font>lr_rect_corner_graph_space.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>ul_rect_corner_graph_space.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,<font color='#979000'>0.0</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#009900'>// adjust slider position now.  
</font>        hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>ul_rect_corner_graph_space.<font color='#BB00BB'>x</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>ul_rect_corner_graph_space.<font color='#BB00BB'>y</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>//              class scrollable_region
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    scrollable_region::
    <b><a name='scrollable_region'></a>scrollable_region</b> <font face='Lucida Console'>(</font>
        drawable_window<font color='#5555FF'>&amp;</font> w,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> events 
    <font face='Lucida Console'>)</font> :
        drawable<font face='Lucida Console'>(</font>w, MOUSE_WHEEL<font color='#5555FF'>|</font>events<font color='#5555FF'>|</font>MOUSE_CLICK<font color='#5555FF'>|</font>MOUSE_MOVE<font face='Lucida Console'>)</font>,
        hsb<font face='Lucida Console'>(</font>w,scroll_bar::HORIZONTAL<font face='Lucida Console'>)</font>,
        vsb<font face='Lucida Console'>(</font>w,scroll_bar::VERTICAL<font face='Lucida Console'>)</font>,
        hscroll_bar_inc<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        vscroll_bar_inc<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        h_wheel_scroll_bar_inc<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        v_wheel_scroll_bar_inc<font face='Lucida Console'>(</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>,
        mouse_drag_enabled_<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>,
        user_is_dragging_mouse<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
    <b>{</b>
        style.<font color='#BB00BB'>reset</font><font face='Lucida Console'>(</font><font color='#0000FF'>new</font> <font color='#BB00BB'>scrollable_region_style_default</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        hsb.<font color='#BB00BB'>set_scroll_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scrollable_region::on_h_scroll<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_scroll_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>scrollable_region::on_v_scroll<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    scrollable_region::
    ~<b><a name='scrollable_region'></a>scrollable_region</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='show'></a>show</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            hsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            vsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='enable'></a>enable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>enable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_z_order'></a>set_z_order</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> order
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_z_order</font><font face='Lucida Console'>(</font>order<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>rect<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// adjust the display_rect_
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>need_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// both scroll bars aren't hidden
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
            <b>{</b>
                vsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                hsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// figure out how many scroll bar positions there should be
</font>            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> hdelta <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> vdelta <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            hdelta <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>hdelta<font color='#5555FF'>+</font>hscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc;
            vdelta <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>vdelta<font color='#5555FF'>+</font>vscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc;

            hsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font>hdelta<font face='Lucida Console'>)</font>;
            vsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font>vdelta<font face='Lucida Console'>)</font>;

            vsb.<font color='#BB00BB'>set_jump_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>vscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
            hsb.<font color='#BB00BB'>set_jump_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>hscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// only hsb is hidden 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
            <b>{</b>
                hsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                vsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#009900'>// figure out how many scroll bar positions there should be
</font>            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> hdelta <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            hdelta <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>hdelta<font color='#5555FF'>+</font>hscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc;

            hsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font>hdelta<font face='Lucida Console'>)</font>;
            vsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;

            hsb.<font color='#BB00BB'>set_jump_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>hscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#009900'>// only vsb is hidden 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
            <b>{</b>
                hsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                vsb.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> vdelta <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            vdelta <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>vdelta<font color='#5555FF'>+</font>vscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc;

            hsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            vsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font>vdelta<font face='Lucida Console'>)</font>;

            vsb.<font color='#BB00BB'>set_jump_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>vscroll_bar_inc<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc<font color='#5555FF'>/</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#009900'>// both are hidden 
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
            <b>{</b>
                hsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                vsb.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font> rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,
                                       rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

            hsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
            vsb.<font color='#BB00BB'>set_max_slider_pos</font><font face='Lucida Console'>(</font><font color='#979000'>0</font><font face='Lucida Console'>)</font>;
        <b>}</b>

        vsb.<font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_length</font><font face='Lucida Console'>(</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// adjust the total_rect_ position by trigging the scroll events
</font>        <font color='#BB00BB'>on_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>rect<font color='#5555FF'>+</font>old<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='horizontal_mouse_wheel_scroll_increment'></a>horizontal_mouse_wheel_scroll_increment</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> h_wheel_scroll_bar_inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='vertical_mouse_wheel_scroll_increment'></a>vertical_mouse_wheel_scroll_increment</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> v_wheel_scroll_bar_inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_horizontal_mouse_wheel_scroll_increment'></a>set_horizontal_mouse_wheel_scroll_increment</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> inc
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        h_wheel_scroll_bar_inc <font color='#5555FF'>=</font> inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_vertical_mouse_wheel_scroll_increment'></a>set_vertical_mouse_wheel_scroll_increment</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> inc
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        v_wheel_scroll_bar_inc <font color='#5555FF'>=</font> inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='horizontal_scroll_increment'></a>horizontal_scroll_increment</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> hscroll_bar_inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='vertical_scroll_increment'></a>vertical_scroll_increment</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> vscroll_bar_inc;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_horizontal_scroll_increment'></a>set_horizontal_scroll_increment</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> inc
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        hscroll_bar_inc <font color='#5555FF'>=</font> inc;
        <font color='#009900'>// call set_size to reset the scroll bars
</font>        <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_vertical_scroll_increment'></a>set_vertical_scroll_increment</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> inc
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        vscroll_bar_inc <font color='#5555FF'>=</font> inc;
        <font color='#009900'>// call set_size to reset the scroll bars
</font>        <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='horizontal_scroll_pos'></a>horizontal_scroll_pos</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>long</u></font> scrollable_region::
    <b><a name='vertical_scroll_pos'></a>vertical_scroll_pos</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_horizontal_scroll_pos'></a>set_horizontal_scroll_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_vertical_scroll_pos'></a>set_vertical_scroll_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> pos
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;

        vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>on_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_pos'></a>set_pos</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font>;
        vsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font>, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        hsb.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font>;

        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> delta_x <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> <font color='#0000FF'><u>long</u></font> delta_y <font color='#5555FF'>=</font> total_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;

        display_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>display_rect_, rect.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, rect.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        total_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>total_rect_, display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>delta_x, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>delta_y<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> scrollable_region::
    <b><a name='mouse_drag_enabled'></a>mouse_drag_enabled</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>return</font> mouse_drag_enabled_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='enable_mouse_drag'></a>enable_mouse_drag</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mouse_drag_enabled_ <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='disable_mouse_drag'></a>disable_mouse_drag</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        mouse_drag_enabled_ <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> scrollable_region::
    <b><a name='display_rect'></a>display_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> display_rect_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='set_total_rect_size'></a>set_total_rect_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#BB00BB'>DLIB_ASSERT</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>width <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> height <font color='#5555FF'>&gt;</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font face='Lucida Console'>(</font>width <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> height <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font>,
                    "<font color='#CC0000'>\tvoid scrollable_region::set_total_rect_size(width,height)</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\twidth and height must be &gt; 0 or both == 0</font>"
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\twidth:  </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> width 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\theight: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> height 
                    <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> "<font color='#CC0000'>\n\tthis: </font>" <font color='#5555FF'>&lt;</font><font color='#5555FF'>&lt;</font> <font color='#0000FF'>this</font>
        <font face='Lucida Console'>)</font>;

        total_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>rectangle</font><font face='Lucida Console'>(</font>width,height<font face='Lucida Console'>)</font>, 
                                display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>,
                                display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font><font color='#0000FF'>static_cast</font><font color='#5555FF'>&lt;</font><font color='#0000FF'><u>long</u></font><font color='#5555FF'>&gt;</font><font face='Lucida Console'>(</font>vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// call this just to reconfigure the scroll bars
</font>        <font color='#BB00BB'>set_size</font><font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>,rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> scrollable_region::
    <b><a name='total_rect'></a>total_rect</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>return</font> total_rect_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='scroll_to_rect'></a>scroll_to_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> r_
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>const</font> rectangle <font color='#BB00BB'>r</font><font face='Lucida Console'>(</font>total_rect_.<font color='#BB00BB'>intersect</font><font face='Lucida Console'>(</font>r_<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        <font color='#0000FF'>const</font> rectangle <font color='#BB00BB'>old</font><font face='Lucida Console'>(</font>total_rect_<font face='Lucida Console'>)</font>;
        <font color='#009900'>// adjust the horizontal scroll bar so that r fits as best as possible
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> distance <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>total_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc;
            hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>distance<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> display_rect_.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> distance <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>right</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>total_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>hscroll_bar_inc<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>hscroll_bar_inc;
            hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>distance<font face='Lucida Console'>)</font>;
        <b>}</b>

        <font color='#009900'>// adjust the vertical scroll bar so that r fits as best as possible
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&lt;</font> display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> distance <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>total_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc;
            vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>distance<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> display_rect_.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> distance <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>r.<font color='#BB00BB'>bottom</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>total_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>display_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font>vscroll_bar_inc<font face='Lucida Console'>)</font><font color='#5555FF'>/</font>vscroll_bar_inc;
            vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>distance<font face='Lucida Console'>)</font>;
        <b>}</b>


        <font color='#009900'>// adjust total_rect_ so that it matches where the scroll bars are now
</font>        total_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>total_rect_, 
                                display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hscroll_bar_inc<font color='#5555FF'>*</font>hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, 
                                display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vscroll_bar_inc<font color='#5555FF'>*</font>vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;

        <font color='#009900'>// only redraw if we actually changed something
</font>        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>total_rect_ <font color='#5555FF'>!</font><font color='#5555FF'>=</font> old<font face='Lucida Console'>)</font>
        <b>{</b>
            parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>display_rect_<font face='Lucida Console'>)</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_wheel_down'></a>on_wheel_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> pos <font color='#5555FF'>=</font> vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>v_wheel_scroll_bar_inc<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> pos <font color='#5555FF'>=</font> hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>+</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>h_wheel_scroll_bar_inc<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_mouse_move'></a>on_mouse_move</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> user_is_dragging_mouse <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> state<font color='#5555FF'>=</font><font color='#5555FF'>=</font>base_window::LEFT<font face='Lucida Console'>)</font>
        <b>{</b>
            point current_delta <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            rectangle <font color='#BB00BB'>new_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>translate_rect</font><font face='Lucida Console'>(</font><font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, drag_origin <font color='#5555FF'>-</font> current_delta<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            new_rect <font color='#5555FF'>=</font> <font color='#BB00BB'>centered_rect</font><font face='Lucida Console'>(</font>new_rect, new_rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hscroll_bar_inc, new_rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vscroll_bar_inc<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>scroll_to_rect</font><font face='Lucida Console'>(</font>new_rect<font face='Lucida Console'>)</font>;
            <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            user_is_dragging_mouse <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>mouse_drag_enabled_ <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#BB00BB'>display_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font face='Lucida Console'>(</font>btn<font color='#5555FF'>=</font><font color='#5555FF'>=</font>base_window::LEFT<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
        <b>{</b>
            drag_origin <font color='#5555FF'>=</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>-</font> <font color='#BB00BB'>point</font><font face='Lucida Console'>(</font><font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, <font color='#BB00BB'>total_rect</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
            user_is_dragging_mouse <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            user_is_dragging_mouse <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_mouse_up'></a>on_mouse_up</b>   <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        user_is_dragging_mouse <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_wheel_up'></a>on_wheel_up</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>lastx,lasty<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> pos <font color='#5555FF'>=</font> vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                vsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>v_wheel_scroll_bar_inc<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_v_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
            <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>need_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <b>{</b>
                <font color='#0000FF'><u>long</u></font> pos <font color='#5555FF'>=</font> hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
                hsb.<font color='#BB00BB'>set_slider_pos</font><font face='Lucida Console'>(</font>pos<font color='#5555FF'>-</font><font face='Lucida Console'>(</font><font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>h_wheel_scroll_bar_inc<font face='Lucida Console'>)</font>;
                <font color='#BB00BB'>on_h_scroll</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            <b>}</b>
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> c
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>draw_scrollable_region_border</font><font face='Lucida Console'>(</font>c, rect, enabled<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> scrollable_region::
    <b><a name='need_h_scroll'></a>need_h_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>total_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#009900'>// check if we would need a vertical scroll bar and if adding one would make us need
</font>            <font color='#009900'>// a horizontal one
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>total_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                total_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>-</font>vsb.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>bool</u></font> scrollable_region::
    <b><a name='need_v_scroll'></a>need_v_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>total_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font>
        <b>{</b>
            <font color='#009900'>// check if we would need a horizontal scroll bar and if adding one would make us need
</font>            <font color='#009900'>// a vertical_scroll_pos one
</font>            <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>total_rect_.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>width</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> 
                total_rect_.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>&gt;</font> rect.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>style<font color='#5555FF'>-</font><font color='#5555FF'>&gt;</font><font color='#BB00BB'>get_border_size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>-</font>hsb.<font color='#BB00BB'>height</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
                <font color='#0000FF'>return</font> <font color='#979000'>true</font>;
            <font color='#0000FF'>else</font>
                <font color='#0000FF'>return</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_h_scroll'></a>on_h_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        total_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>total_rect_, display_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>hscroll_bar_inc<font color='#5555FF'>*</font>hsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, total_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>display_rect_<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>events_are_enabled</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> scrollable_region::
    <b><a name='on_v_scroll'></a>on_v_scroll</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        total_rect_ <font color='#5555FF'>=</font> <font color='#BB00BB'>move_rect</font><font face='Lucida Console'>(</font>total_rect_, total_rect_.<font color='#BB00BB'>left</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>, display_rect_.<font color='#BB00BB'>top</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>-</font>vscroll_bar_inc<font color='#5555FF'>*</font>vsb.<font color='#BB00BB'>slider_pos</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>;
        parent.<font color='#BB00BB'>invalidate_rectangle</font><font face='Lucida Console'>(</font>display_rect_<font face='Lucida Console'>)</font>;
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>events_are_enabled</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>
            <font color='#BB00BB'>on_view_changed</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// class popup_menu_region 
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font><font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    popup_menu_region::
    <b><a name='popup_menu_region'></a>popup_menu_region</b><font face='Lucida Console'>(</font>  
        drawable_window<font color='#5555FF'>&amp;</font> w
    <font face='Lucida Console'>)</font> :
        drawable<font face='Lucida Console'>(</font>w,MOUSE_CLICK <font color='#5555FF'>|</font> KEYBOARD_EVENTS <font color='#5555FF'>|</font> FOCUS_EVENTS <font color='#5555FF'>|</font> WINDOW_MOVED<font face='Lucida Console'>)</font>,
        popup_menu_shown<font face='Lucida Console'>(</font><font color='#979000'>false</font><font face='Lucida Console'>)</font>
    <b>{</b>

        menu_.<font color='#BB00BB'>set_on_hide_handler</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font color='#0000FF'>this</font>,<font color='#5555FF'>&amp;</font>popup_menu_region::on_menu_becomes_hidden<font face='Lucida Console'>)</font>;
        <font color='#BB00BB'>enable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    popup_menu_region::
    ~<b><a name='popup_menu_region'></a>popup_menu_region</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b> 
        <font color='#BB00BB'>disable_events</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='set_size'></a>set_size</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> width, 
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> height
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> <font color='#BB00BB'>resize_rect</font><font face='Lucida Console'>(</font>rect,width,height<font face='Lucida Console'>)</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='set_rect'></a>set_rect</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> rectangle<font color='#5555FF'>&amp;</font> new_rect
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        rect <font color='#5555FF'>=</font> new_rect;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    popup_menu<font color='#5555FF'>&amp;</font> popup_menu_region::
    <b><a name='menu'></a>menu</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>return</font> menu_;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='hide'></a>hide</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='disable'></a>disable</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        auto_mutex <font color='#BB00BB'>M</font><font face='Lucida Console'>(</font>m<font face='Lucida Console'>)</font>;
        drawable::<font color='#BB00BB'>disable</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
        popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_keydown'></a>on_keydown</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> key,
        <font color='#0000FF'><u>bool</u></font> is_printable,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> state
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>forwarded_on_keydown</font><font face='Lucida Console'>(</font>key, is_printable, state<font face='Lucida Console'>)</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>

        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>key <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font><font face='Lucida Console'>)</font>base_window::KEY_ESC<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_menu_becomes_hidden'></a>on_menu_becomes_hidden</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_focus_lost'></a>on_focus_lost</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_focus_gained'></a>on_focus_gained</b> <font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_window_moved'></a>on_window_moved</b><font face='Lucida Console'>(</font>
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='on_mouse_down'></a>on_mouse_down</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> btn,
        <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> ,
        <font color='#0000FF'><u>long</u></font> x,
        <font color='#0000FF'><u>long</u></font> y,
        <font color='#0000FF'><u>bool</u></font> 
    <font face='Lucida Console'>)</font>
    <b>{</b>
        <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>enabled <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> <font color='#5555FF'>!</font>hidden <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> rect.<font color='#BB00BB'>contains</font><font face='Lucida Console'>(</font>x,y<font face='Lucida Console'>)</font> <font color='#5555FF'>&amp;</font><font color='#5555FF'>&amp;</font> btn <font color='#5555FF'>=</font><font color='#5555FF'>=</font> base_window::RIGHT<font face='Lucida Console'>)</font>
        <b>{</b>
            <font color='#0000FF'><u>long</u></font> orig_x, orig_y;
            parent.<font color='#BB00BB'>get_pos</font><font face='Lucida Console'>(</font>orig_x, orig_y<font face='Lucida Console'>)</font>;
            menu_.<font color='#BB00BB'>set_pos</font><font face='Lucida Console'>(</font>orig_x<font color='#5555FF'>+</font>x, orig_y<font color='#5555FF'>+</font>y<font face='Lucida Console'>)</font>;
            menu_.<font color='#BB00BB'>show</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>true</font>;
        <b>}</b>
        <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>popup_menu_shown<font face='Lucida Console'>)</font>
        <b>{</b>
            menu_.<font color='#BB00BB'>hide</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>;
            popup_menu_shown <font color='#5555FF'>=</font> <font color='#979000'>false</font>;
        <b>}</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
    <font color='#0000FF'><u>void</u></font> popup_menu_region::
    <b><a name='draw'></a>draw</b> <font face='Lucida Console'>(</font>
        <font color='#0000FF'>const</font> canvas<font color='#5555FF'>&amp;</font> 
    <font face='Lucida Console'>)</font> <font color='#0000FF'>const</font>
    <b>{</b>
    <b>}</b>

<font color='#009900'>// ----------------------------------------------------------------------------------------
</font>
<b>}</b>

<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_BASE_WIDGETs_CPP_ 
</font>

</pre></body></html>